package Ep04_String._0541;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/3/18 13:50
 * 说明：力扣 0541 反转字符串II
 */

public class Mine {
    public String reverseStr(String s, int k) {
        if (s.length() == 0 || s.length() == 1){
            return s;
        }
        char[] strC = s.toCharArray();
        for (int i = 0; i < strC.length; i+=2*k) {
            int left = i;
            int right = Math.min(strC.length-1, left + k - 1);
            while (left < right) {
                char temp = strC[left];
                strC[left] = strC[right];
                strC[right] = temp;

                left++;
                right--;
            }
        }
        return new String(strC);
    }
}
